package com.dream.dynamic_datasource.service.login.impl;

import com.dream.dynamic_datasource.dto.UserLoginDto;
import com.dream.dynamic_datasource.entity.user.Db;
import com.dream.dynamic_datasource.entity.user.User;
import com.dream.dynamic_datasource.mapper.UserMapper;
import com.dream.dynamic_datasource.service.login.LoginService;
import com.dream.dynamic_datasource.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: Luo
 * @create: 2020-07-14 16:20
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private JwtUtil jwtUtil;
    @Autowired
    private UserMapper userMapper;


    @Override
    public String login(UserLoginDto userLoginDto) {
        User user = userMapper.selectByUsernameAndPassword(userLoginDto);
        List<Db> dbs = userMapper.selectDbList();
        return jwtUtil.geneJsonWebToken(user);
    }

    @Override
    public User getUser() {
        return jwtUtil.getLogUser();
    }


}
